package com.waikuai.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.waikuai.shop.entity.Role;
import com.waikuai.shop.mapper.RoleMapper;
import com.waikuai.shop.service.RoleService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 角色服务实现类
 * @author waikuai
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class RoleServiceImpl implements RoleService {

    private final RoleMapper roleMapper;

    @Override
    public List<Role> getAllEnabledRoles() {
        LambdaQueryWrapper<Role> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Role::getStatus, 1)
                .eq(Role::getDeleted, 0)
                .orderByAsc(Role::getId);
        return roleMapper.selectList(wrapper);
    }

    @Override
    public List<Role> getRolesByUserId(Long userId) {
        return roleMapper.findByUserId(userId);
    }

    @Override
    public Role findByRoleCode(String roleCode) {
        return roleMapper.findByRoleCode(roleCode);
    }
}

